/***********************************************************************************************************************
**	filename: cfg_info.h
**	author: Echo Zhang @2021-05-23
**  e-mail: not_xx@126.com
***********************************************************************************************************************/

#ifndef CFG_INFO_INCLUDED
#define CFG_INFO_INCLUDED

#include <stdio.h>
#include "../user_types.h"

#ifdef __arm__
#define _CFG_FILE_NAME                      "/oemdata/config.json"
#else
#define _CFG_FILE_NAME                      "config.json"
#endif

struct mqtt_info {
    char addr[20];
    ui16 port;
    char user[128];
    char passwd[128];
};

struct dial_apn {
    char apn[128];
    char user[128];
    char passwd[128];
};

struct serial_info {
    char name[20];
    int baud;
    ui8 databit;
    ui8 stopbit;
    ui8 parity;
    ui8 flow;
};

struct cfg_info {
    struct mqtt_info *mqttCfg;
    struct dial_apn *dialCfg;
    struct serial_info *serialCfg;
    uint8_t isDebugOut;
    char *device_id;
};

bool cfg_info_load(const char *filename, struct cfg_info *cfgInfo);
bool cfg_info_save(const char *filename, const struct cfg_info *cfgInfo);
void print_config(const struct cfg_info *cfgInfo);

#endif	/* CFG_INFO_INCLUDED */

/***********************************************************************************************************************
**	endline
***********************************************************************************************************************/
